<template>
	<view>
		<view class="shadow_con">
			<view class="u-margin-bottom-30">分类名称：</view>
			<input v-model="name" type="text" placeholder="请输入分类名称">
			<view class="u-margin-bottom-30">分类描述：</view>
			<input v-model="description" type="text" placeholder="请输入分类描述">
			<view class="u-flex u-row-between">
				<view class="dis_inl_blo u-text-center" style="margin:0 40rpx;">
					<view>上传图片</view>
					<u-upload :action="action" :fileList="fileList" @on-success="successimg" @on-remove="deletePic" maxCount="1"></u-upload>
				</view>
				<view class="dis_inl_blo u-text-center" style="margin:0 40rpx;">
					<view>上传图标</view>
					<u-upload :action="action" :fileList="fileList1" @on-success="successimg1" @on-remove="deletePic1" maxCount="1"></u-upload>
				</view>
			</view>
			<button class="btn_con" @click="confirm">发布</button>
		</view>
		<!-- 弹框提示 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		releaseTopic
	} from "@/service/indexService.js";
	export default {
		data () {
			return {
				detail:{},
				action:'https://admin.gslhzhwy.com/api/upload/file',
				fileList:[],
				fileList1:[],
				
				id:0,
				name:'',
				description:'',
				image:'',
				icon:''
			}
		},
		onLoad(options) {
			let item=JSON.parse(decodeURIComponent(options.item));
			this.name=item.name;
			this.description=item.description;
			this.image=item.image;
			this.icon=item.icon;
			this.fileList=[{url:item.image}];
			this.fileList1=[{url:item.icon}];
			this.id=item.id;
		},
		methods:{
			successimg:function(e){
				if (e.code == 1) {
					this.image=e.data.url;
				}
			},
			// 删除图片
			deletePic(event) {
				this.image='';
			},
			successimg1:function(e){
				if (e.code == 1) {
					this.icon=e.data.url;
				}
			},
			// 删除图片
			deletePic1(event) {
				this.icon='';
			},
			confirm:function(){
				releaseTopic({
					gid:this.id,
					name:this.name,
					description:this.description,
					image:this.image,
					icon:this.icon
				}).then(res=>{
					if(res.code==200){
						this.$refs.uToast.show({
							type: 'success',
							title: '编辑成功',
							icon:false
						})
						setTimeout(function(){
							uni.navigateBack()
						},2000)
					}else{
						this.$refs.uToast.show({
							type: 'error',
							title: res.msg,
							icon:false
						})
					}
				});
				
			}
		}
	}
</script>

<style lang="scss">
	.shadow_con{
		padding:80rpx 20rpx;
	}
	.shadow_con input{
		width:93%;
		height:70rpx;
		padding:0 20rpx;
		margin-bottom:30rpx;
		border-radius: 10rpx;
		border:1rpx solid #ccc;
		background-color: #fafafa;
	}
	.btn_con{
		height:70rpx;
		line-height: 70rpx;
		font-size: 30rpx;
		border-radius: 35rpx;
		background-image: url('https://resourse.cnlhjt.com/upload/20220825/d1aa35c1d129137d9b12c8f34e59c5bc.png');
		background-size: 100% 70rpx;
		color:#fff;
		margin-top:180rpx;
	}
</style>
